const app = getApp();
Page({
  data: {
   canIUse: wx.canIUse('button.open-type.getUserInfo'),
   userName:'',
   userImg:'',
   usermotto:''
  },
  onLoad: function() {
   // 查看是否授权
   wx.getSetting({
        success: function(res){
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: (res) => {
              console.log(res.userInfo)
            }
          })
        }
        }
   })
},


  bindGetUserInfo: function(e) {
   console.log(e.detail.userInfo)
   const userInfo = e.detail.userInfo
   const str = "Welcome to 52Hz"
   this.setData({
    userName:userInfo.nickName,
    userImg:userInfo.avatarUrl,
    usermotto: str
  })
    app.globalData.userInfo['userName'] = userInfo.nickName;
    app.globalData.userInfo['userImg'] = userInfo.avatarUrl;

    //console.log(app.globalData.userInfo)
    //创建新用户
   // this.newUser();

   
  },

 //创建用户
 newUser(){
  wx.request({
    url: 'http://49.233.35.127/Wx/Adduser',
   // method:'POST',
    data:{
      name:this.data.userName,
      img:this.data.userImg

    },
    success:(res)=>{
      console.log(res,"创建成功")
    }
  })
 },



  gogogo(){
    wx.reLaunch({
      url: '../test/test',
    })
  }
 })
 
 